<template>
	<scroll-view style="background-color: #f2f5f7;">
		<view style="width: 100%;" v-for="(item,index) in sellInfo">	
			<view class="userItem" :key="index"
				style="height: 400rpx;background-color:white;margin-top:20rpx;margin-left: 10rpx;margin-right: 10rpx;margin-bottom: 20rpx;border-radius: 50rpx;padding-top: 30rpx;">
				<view style="display: flex;align-items: center;padding-left: 50rpx;margin-bottom: 30rpx;">
					<p>买家：</p>
					<image :src="imgUrlConfig+item.sell.img[0]" v-if="(!userImg(item.userId.img[0]))" mode="" style="width: 50rpx;height: 50rpx;"></image>
					<image :src="item.userId.img[0]" v-if="userImg(item.userId.img[0])" mode="" style="width: 50rpx;height: 50rpx;"></image>
					<span
						style="display: inline-block;padding-left: 12rpx;font-weight: bold;font-size:28rpx ;line-height:50rpx;">{{item.userId.nickName}}</span>
				</view>
				<view style="display: flex;align-items:center;justify-content: space-around;">
					<image :src="imgUrlConfig+item.articleId.images[0]" mode=""
						style="width: 200rpx;height: 200rpx; border-radius: 30rpx;"></image>
					<view style="width: 320rpx;">
						<p style="display: inline-block;font-size: 28rpx;width:320rpx;height:200rpx;">
							{{item.articleId.desc.substring(0,20)+"..."}}
						</p>
						<p style="display: inline-block;font-size: 28rpx;width:320rpx;height:200rpx;font-weight: bold;">
							{{ timingRen(item.articleId.time)}}卖出
						</p>
						<!--  -->
					</view>
					<view style="text-align: center;width: 100rpx;">
						<p style="font-size: 28rpx;"><span style="font-size: 24rpx;">￥</span><span
								style="color:red;">{{item.articleId.price}}</span></p>
					</view>
		
				</view>
				<view style="display: flex;flex-direction: row-reverse;padding-right: 20rpx;">
					<view @click="lookInfo(userNowId,item)"
						style="margin-top:20rpx;display: inline-block;display:flex;width:160rpx;background-color:#78cdd1;border-radius:26rpx;line-height:60rpx;justify-content: center;font-size: 26rpx;">
						查看详情</view>
				</view>
			</view>
		</view>
			
		</view>
	</scroll-view>
</template>

<script>
	import timeFun from '../../../utils/time.js'
	export default {
		created() {
			// 获取用户订单信息
			const userNow = this.$store.state.user;
			this.userNowId=userNow._id;
			console.log(timeFun)
			uni.request({
				url:`http://localhost:3001/orders/listFavorite`,
				method:'GET',
		        success: (res) => {
		        	this.allorders=res.data;
					console.log("52hang",this.allorders)
					this.allorders.map((item,index)=>{
						if((item.sell._id)==(this.$store.state.user._id)){
							console.log('属于你的该条订单的信息可以查找是谁买的',item)
							this.sellInfo.push(item);
							console.log(this.sellInfo)
						}
					})
		        }
			})
			// 将商品信息ID发出查找卖家信息
			// for( var item of this.userInfo){
			// 	uni.request({
			// 		url:`http://localhost:3001/goods/${item.articleId._id}`,
			// 		method:'GET',
			// 		success: (res) => {
			// 			this.sellInfo.push(res.data);
			// 		}
			// 	})
			// })
		},
		data() {
			return {
				// 请求图片的
				imgUrlConfig: 'http://localhost:3002',
				userNowId: "",
				allorders: [],
				sellInfo: [],
				
			}
		},
		methods: {
			wtf() {
				console.log(1)
			},
			userImg(url){
				var str=new RegExp("http");
				return str.test(url)
			},
			lookInfo(id,artData){
				console.log('第93行',artData.articleId);
				this.$store.commit('addGoods',artData.articleId);
				uni.navigateTo({
				        url: '/pages/goodsInfo/goodsInfo?_id='+artData.articleId._id
				      });
			},
			// 时间戳转换
			timingRen(time){
				return timeFun.getFormatTime((new Date(time)).getTime());
			}
		}
	}
</script>

<style scoped>
	body{
		background-color: #f2f5f7;
	}

	.userItem {}
</style>
